#include "Figure.h"
//------------------------------------------------------------------------
// Static Methods
//------------------------------------------------------------------------
int Figure::ID_Counter = 1 << 24;
//------------------------------------------------------------------------
Figure::FigurePointerVec Figure::createFigures(IrrlichtDevice * const dev, ITriangleSelector * const selector)
{
	Figure::VecBool2D body(1, std::vector<bool>(1, true));

	FigurePointerVec v;

	v.push_back(std::unique_ptr<Figure>(new Figure(body, selector, dev)));

	return v;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// Kon-Destruktoren
//------------------------------------------------------------------------
Figure::Figure(VecBool2D const& binaryFigure, ITriangleSelector * const selector, IrrlichtDevice * const dev)
	: Entity(dev), m_binaryFigure(binaryFigure)
{
	this->m_fig = this->m_sceneMgr->addCubeSceneNode(Global::Konstanten::gc_Rastereinheit, nullptr, -1, vector3df(0.0f, 100.0f, 0.0f));
	this->m_fig->setMaterialFlag(EMF_LIGHTING, false);
	this->m_fig->setMaterialTexture(0, this->m_driver->getTexture("media/models/fireball.bmp"));

	this->m_fig->setTriangleSelector(selector);
	auto box = this->m_fig->getBoundingBox();
	this->m_fig->addAnimator(this->m_sceneMgr->createCollisionResponseAnimator(selector, this->m_fig, box.MaxEdge));

	this->m_fig->setID(ID_Counter++);
}
//------------------------------------------------------------------------
// Methoden
//------------------------------------------------------------------------
void Figure::yaw(bool common)
{
}
//------------------------------------------------------------------------
void Figure::pitch(bool common)
{
}
//------------------------------------------------------------------------
void Figure::roll(bool common)
{
}
//------------------------------------------------------------------------
void Figure::move(float timefactor, vector2df move, Camera const& cam)
{
	auto cube = this->m_fig;
	vector3df newPos = cube->getPosition();
	vector3df dir = cam.getUpVec().crossProduct(-cam.getPosition());
	
	vector2df trans = timefactor * move * Global::Konstanten::gc_CursorSpeed;

	// TODO: Optimierungspotenzial wegen Wurzelberechnung in Normalize
	newPos += dir.normalize() * trans.X;
	vector3df newDir = dir.crossProduct(cam.getPosition());
	newPos += newDir.normalize() * trans.Y;

	cube->setPosition(newPos);
}
//------------------------------------------------------------------------
int Figure::getID() const
{
	return this->m_fig->getID();
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------


